package com.ambulance.project.manager.service.impl;

import com.ambulance.project.manager.domain.BizDispatchdevice;
import com.ambulance.project.manager.mapper.BizDispatchdeviceMapper;
import com.ambulance.project.manager.service.IBizDispatchdeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.util.List;

/**
 * 调度车载设备记录信息Service业务层处理
 *
 * @author zr
 * @date 2020-07-08
 */
@Service
public class BizDispatchdeviceServiceImpl implements IBizDispatchdeviceService
{
    @Autowired
    private BizDispatchdeviceMapper bizDispatchdeviceMapper;

    /**
     * 查询调度车载设备记录信息
     *
     * @param deviceRecordID 调度车载设备记录信息ID
     * @return 调度车载设备记录信息
     */
    @Override
    public BizDispatchdevice selectBizDispatchdeviceById(Long deviceRecordID)
    {
        return bizDispatchdeviceMapper.selectBizDispatchdeviceById(deviceRecordID);
    }

    @Override
    public List<BizDispatchdevice> selectBizDispatchdeviceById2(Long dispatchCaseID)
    {

        final List<BizDispatchdevice> bizDispatchdevices = bizDispatchdeviceMapper.selectBizDispatchdeviceById2(dispatchCaseID);
        for (BizDispatchdevice item: bizDispatchdevices) {
            Duration duration = Duration.between(item.getStartTime(), item.getEndTimes());
            Long minutes = duration.getSeconds();
            item.setInterval(minutes.toString());
        }
        return bizDispatchdevices;
    }
    /**
     * 查询调度车载设备记录信息列表
     *
     * @param bizDispatchdevice 调度车载设备记录信息
     * @return 调度车载设备记录信息
     */
    @Override
    public List<BizDispatchdevice> selectBizDispatchdeviceList(BizDispatchdevice bizDispatchdevice)
    {
        return bizDispatchdeviceMapper.selectBizDispatchdeviceList(bizDispatchdevice);
    }

    /**
     * 新增调度车载设备记录信息
     *
     * @param bizDispatchdevice 调度车载设备记录信息
     * @return 结果
     */
    @Override
    public int insertBizDispatchdevice(BizDispatchdevice bizDispatchdevice)
    {
        return bizDispatchdeviceMapper.insertBizDispatchdevice(bizDispatchdevice);
    }

    /**
     * 修改调度车载设备记录信息
     *
     * @param bizDispatchdevice 调度车载设备记录信息
     * @return 结果
     */
    @Override
    public int updateBizDispatchdevice(BizDispatchdevice bizDispatchdevice)
    {
        return bizDispatchdeviceMapper.updateBizDispatchdevice(bizDispatchdevice);
    }

    /**
     * 批量删除调度车载设备记录信息
     *
     * @param deviceRecordIDs 需要删除的调度车载设备记录信息ID
     * @return 结果
     */
    @Override
    public int deleteBizDispatchdeviceByIds(Long[] deviceRecordIDs)
    {
        return bizDispatchdeviceMapper.deleteBizDispatchdeviceByIds(deviceRecordIDs);
    }

    /**
     * 删除调度车载设备记录信息信息
     *
     * @param deviceRecordID 调度车载设备记录信息ID
     * @return 结果
     */
    @Override
    public int deleteBizDispatchdeviceById(Long deviceRecordID)
    {
        return bizDispatchdeviceMapper.deleteBizDispatchdeviceById(deviceRecordID);
    }
}
